package com.serverTechnology.resource.config;

import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition;
import cn.stylefeng.roses.kernel.sys.modular.resource.cache.RedisResourceCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @program: AssembleIcpCode
 * @ClassName RedisResourceTemplateConfig
 * @author: ayetony miao
 * @create: 2023-12-18 19:04
 **/
@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class RedisResourceTemplateConfig {

    /**
     * 资源缓存
     *
     * @author fengshuonan
     * @since 2022/11/8 23:27
     */
    @Bean
    public CacheOperatorApi<ResourceDefinition> resourceCache(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, ResourceDefinition> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
        return new RedisResourceCache(redisTemplate);
    }

}
